import {defineStore} from "pinia";
import {ref} from "vue";
import type {User} from "@/types/user";

export const useUserStore = defineStore('userInfo', () => {
        const userInfoData = ref<User>()
        const dailyLoginTime = ref(0) // 用户每日登录的时间
        const checkCalendarNotice = ref(false)
        const clearUserInfo = () => {
            userInfoData.value = undefined
            uni.removeTabBarBadge({
                index: 3
            })
        }
        return {userInfoData, clearUserInfo, dailyLoginTime, checkCalendarNotice}
    },
    {
        persist: {
            storage: {
                setItem(key, value) {
                    uni.setStorageSync(key, value)
                },
                getItem(key) {
                    return uni.getStorageSync(key)
                },
            },
            // 确保将 dailyLoginTime 也持久化
            paths: ['userInfoData', 'dailyLoginTime', 'checkCalendarNotice'], // 指定要持久化的状态
        },
    }
)